import { RouteObject as RRouteObject, useRoutes, Navigate } from 'react-router-dom'
import Layout from '@/layouts'
import homeRoutes from './home'
import customerRoutes from './customer'
import accountRoutes from './account'
import channelRoutes from './channel'
import productRoutes from './product'
import workRoutes from './work'
import secondPageRoutes from './second-page'

const routes = [
	{
		path: '/login',
		element: <Layout layoutApply='loginPage' />,
	},
	{
		path: '/second-page',
		element: <Layout layoutApply='secondPage' />,
		children: [
			...secondPageRoutes
		]
	},
  {
    path: '/',
    element: <Layout layoutApply='mainPage' />,
    children: [
			{
				index: true, // 默认页面
				element: <Navigate to='/home' />,
				meta: {
					requireAuth: false,
					title: '首页',
					key: 'home'
				}
			},
			...homeRoutes,
			...customerRoutes,
			...accountRoutes,
			...channelRoutes,
			...productRoutes,
			...workRoutes,
    ]
  },
	{
		path: '*',
		element: <Navigate to='/home' />
	}
]

const Router = () => useRoutes(routes as RRouteObject[])

export default Router
